-
Notifications
You must be signed in to change notification settings - Fork 6.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix error case memory bug in GetHostName() #11544
Conversation
cb35690
to
37a6a2c
Compare
@jowlyzhang has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
37a6a2c
to
532de97
Compare
@jowlyzhang has updated the pull request. You must reimport the pull request before landing. |
@jowlyzhang has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix! I suggest a more clear and direct summary like "Fix error case memory bug in GetHostName()". In case you were taking inspiration from some of the soft language in my PR #11538, that is kind of a special case where it's hard to promise what is actually safe usage during static destruction and we nevertheless need to make reasonable accommodations to avoid bugs or crashes, as there might not be a clear path to guaranteed safe usage.
In this case, the old code was completely unsafe (on an error handling path).
Rant: It would be nice to deprecate and get rid of this API with its C-style calling conventions, but that's probably more work than it's worth. Back to the important things.
Thanks Peter for the review and the suggested summary. You are right that this is not just a good-to-have improvement, but an absolutely necessary fix for an incorrectly handled error case. |
532de97
to
25687c2
Compare
@jowlyzhang has updated the pull request. You must reimport the pull request before landing. |
@jowlyzhang has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@jowlyzhang merged this pull request in 6649978. |
Fix the error handling in
GetHostName
for non EFAULT, non EINVAL error. Current handling will cause stack overflow when non null-terminated c style string is inname
, e.g. ENAMETOOLONG, when thename
buffer is not big enough and the host name is truncated.Test Plan: